import { defineConfig, loadEnv } from 'vite'
import vue from '@vitejs/plugin-vue'
import path from 'path'
import zipPack from "vite-plugin-zip-pack";

// https://vitejs.dev/config/
export default defineConfig(({ mode }) => {
  process.env = { ...process.env, ...loadEnv(mode, process.cwd()) };

  const API_TARGET = process.env.VITE_APP_API_URL;

  return {
    server: {
      host: '0.0.0.0',
      port: 80,
      allowedHosts: []
    },
    plugins: [
      vue(),
      zipPack({
        inDir: 'dist', // 输入文件夹
        outDir: 'archive', // 输出文件夹
        outFileName: 'fdist.zip', // 压缩包的文件名
        pathPrefix: '', // 可以为压缩包中的文件指定路径前缀
        enableLogging: false, // 是否启用日志输出，默认启用
      })
    ],
    resolve: {
      alias: {
        '@': path.resolve(__dirname, 'src')
      },
      extensions: ['.js', '.vue', '.json']
    },
    css: {
      preprocessorOptions: {
        less: {
          javascriptEnabled: true
        }
      }
    }
  }
})
